package src.com.foreknow.demo6;

import sun.management.snmp.jvmmib.JVM_MANAGEMENT_MIBOidTable;

import javax.imageio.stream.ImageInputStream;
import java.util.Scanner;

/**
 * 创建一个学生类，该累的属性包括姓名，学号，成绩， 设计一个方法按照成绩从高到低的输出姓名 学号 成绩
 * 1. 发现类以及类的属性
 * 2.排序
 * 3.需要创建三个学生对象 并将对象保存到数组当中，然后调用方法来实现排序
 */
public class Student {
    //定义一个排序的方法（有没有返回值类型以及参数）
    private String name;
    private int id;
    private double score;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getScore() {
        return score;
    }

    public void setScore(double score) {
        this.score = score;
    }
    public void descScore(Student[] students) {
        for (int i = 1; i < students.length; i++) {
            for (int j = 0; j < students.length - i; j++) {
                if (students[j].getScore() > students[j + 1].getScore()) {
                    Student temp = students[j + 1];
                    students[j + 1] = students[j];
                    students[j] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Student[] students1 = new Student[3];
        for (int i = 0; i < 3; i++) {
            Student student = new Student();
            Scanner input = new Scanner(System.in);
            System.out.println("请输入姓名：");
            String name = input.next();
            student.setName(name);
            System.out.println("请输入学号：");
            int id = input.nextInt();
            student.setId(id);
            System.out.println("请输入成绩：");
            double score = input.nextDouble();
            student.setScore(score);
            students1[i] = student;
        }
        for (int i = 0; i < students1.length; i++) {
            Student student = students1[i];
            System.out.println("姓名：" + student.getName() + "学号：" + student.getId() + "成绩：" + student.getScore());
        }
    }
}


























